package com.techsoft;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public interface DataExecutor {

	/**
	 * 设置参数值
	 * 
	 * @param param
	 * @param executor
	 * @param conn
	 * @throws SQLException
	 * @throws IOException
	 * @throws DBException
	 */
	public void setParam(SQLParam param, CallableStatement executor,
			Connection conn) throws DBException;

	/**
	 * 取得返回参数值
	 * 
	 * @param param
	 * @param executor
	 * @param conn
	 * @param result
	 * @throws SQLException
	 * @throws DBException
	 * @throws IOException
	 */
	public void getParam(SQLParam param, CallableStatement executor,
			Connection conn) throws DBException;

	/**
	 * 取得一查询语句的元数据
	 * 
	 * @param sql
	 * @param isCursor
	 * @param conn
	 * @return
	 * @throws SQLException
	 */
	public List<MetaData> queryMetaData(String sql, boolean isCursor,
			Connection conn) throws DBException;

	/**
	 * 取得语句的参数
	 * 
	 * @param sql
	 * @param conn
	 * @return
	 * @throws SQLException
	 */
	public Map<String,Object> queryParams(String sql, Connection conn)
			throws DBException;

	/**
	 * 查询数据，并返回结果集，每一行数据用一个Map表示
	 * 
	 * @param sql
	 * @param isCursor
	 * @param params
	 * @param conn
	 * @return
	 * @throws SQLException
	 * @throws IOException
	 * @throws DBException
	 */
	public List<Map<String, Object>> queryData(String sql, boolean isCursor,
			List<SQLParam> params, Connection conn) throws DBException;

	/**
	 * @param sql
	 * @param isCursor
	 * @param pageNumber
	 * @param pageSize
	 * @param params
	 * @param conn
	 * @return
	 * @throws DBException
	 */
	public List<Map<String, Object>> queryDataByPage(String sql,
			boolean isCursor, Integer pageNo, Integer pageSize,
			List<SQLParam> params, Connection conn) throws DBException;

	/**
	 * 保存数据，并返回输出参数的值
	 * 
	 * @param sql
	 * @param params
	 * @param conn
	 * @return
	 * @throws SQLException
	 * @throws IOException
	 * @throws DBException
	 */
	public Map<String, Object> saveData(String sql, List<SQLParam> params,
			Connection conn) throws DBException;

	/**
	 * 序列化数据集，每一行用一个Map表示
	 * 
	 * @param rs
	 * @param conn
	 * @return
	 * @throws SQLException
	 * @throws IOException
	 * @throws DBException
	 */
	public List<Map<String, Object>> serializeResultSet(ResultSet rs,
			Connection conn) throws DBException;

	/**
	 * 对于分页语句， 得到总记录数， 以便前台进行分页
	 * 
	 * @param querysql
	 * @param params
	 * @param conn
	 * @return Integer
	 * @throws SQLException
	 * @throws IOException
	 * @throws DBException
	 */
	public Integer queryRecordCount(String querysql, List<SQLParam> params,
			Connection conn) throws DBException;
}
